<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
  <title>玩玩而已</title>
    <link rel="stylesheet" type="text/css" href="jslib/ext-3.4.0/resources/css/ext-all.css" />
    <style type="text/css">
    html, body {
        font:normal 12px verdana;
        margin:0;
        padding:0;
        border:0 none;
        overflow:hidden;
        height:100%;
    }
    p {
        margin:5px;
    }
    .settings {
        background-image:url(jslib/ext-3.4.0/examples/shared/icons/fam/folder_wrench.png);
    }
    .nav {
        background-image:url(jslib/ext-3.4.0/examples/shared/icons/fam/folder_go.png);
    }
    </style>

    <!-- GC -->
    <!-- LIBS -->
    <script type="text/javascript" src="jslib/ext-3.4.0/adapter/ext/ext-base.js"></script>
    <!-- ENDLIBS -->

    <script type="text/javascript" src="jslib/ext-3.4.0/ext-all.js"></script>

    <!-- EXAMPLES -->
    <script type="text/javascript" src="jslib/ext-3.4.0/examples/shared/examples.js"></script>
    
    <script type="text/javascript" src="jslib/basic.js"></script>
    <script type="text/javascript" src="jslib/layout-browser.js"></script>
    <script type="text/javascript">
    
    Ext.onReady(function() {  
        var cum = new Ext.grid.ColumnModel([{  
            header:'类型ID', 
            dataIndex: 'sortId',  
            editor: new Ext.grid.GridEditor(  
                new Ext.form.TextField({  
                    allowBlank: false  
                })),  
            }, {  
                header: '类型姓名',   
                dataIndex: 'sortName',  
                editor: new Ext.grid.GridEditor(  
                    new Ext.form.TextField({  
                        allowBlank: false  
                    }))  
            },{  
                header: '父类型',   
                dataIndex: 'parentSort',  
                editor: new Ext.grid.GridEditor(  
                    new Ext.form.TextField({  
                        allowBlank: false  
                    }))  
            }, {  
                header: '类型描述',   
                dataIndex: 'sortDescn',  
                editor: new Ext.grid.GridEditor(  
                    new Ext.form.TextField({  
                        allowBlank: false  
                    }))  
            }, {  
                header: '日期',   
                dataIndex: 'kdtime',
                editor: new Ext.grid.GridEditor(  
                    new Ext.form.DateField({  
                        allowBlank: false  
                    }))  
            }]);  
        
      var cumdata = [  
          ['0', 'String', '全部', '字符串类型', '2010-05-22'],  
          ['1', 'String', 'Object', '字符串类型', '2010-05-22'],  
          ['2', 'Integer', 'Object', '整数类型', '2010-06-07'],  
          ['3', 'GridView', 'Observable', '用户界面的封装', '2010-05-05'],  
          ['4', 'ColumnModel', 'Observable', 'Grid列模型的默认实现', '2001-07-05'],  
          ['5', 'EditorGridPanel', 'GridPanel', '用于在指定某些的列可以编辑单元格', '2007-06-01'],  
          ['6', 'PropertyRecord', 'Object', '用于表示一对"名称/值"的数据', '2009-09-03']  
      ];  
        
      var store = new Ext.data.Store({  
          proxy: new Ext.data.MemoryProxy(cumdata),  
          reader: new Ext.data.ArrayReader({}, [  
               {name: 'sortId'},  
               {name: 'sortName'},  
               {name: 'parentSort'},  
               {name: 'sortDescn'},  
               {name: 'kdtime'}  
          ])  
      });  
        
      store.load();  
      
      var onViewTypeSelect = function(_combo){
    	  var _type = _combo.getValue();
    	  if(_type=="全部"){
    		  store.clearFilter();
    	  }else{
    		  store.filter("parentSort",_combo.getValue());
    	  }
      }
      
      var cumgrid = new Ext.grid.EditorGridPanel({  
          renderTo: 'cumGrid',  
          store: store,  
          stripeRows: true, 
          tbar:[{
          	text:"保存"
          },"-",{
        	  id:"_combo",
        	  header:"类型",
        	  mode:"local",
        	  displayField:"parentSort",
        	  xtype:"combo",
        	  value:"Object",
        	  store:store,
        	  listeners:{
        		  "select":{
        			  fn:this.onViewTypeSelect,
        			  scope:this
        		  }
        	  }
        	  
          }],
          viewConfig: {  
              forceFit: true,  
              scrollOffset: 30,  
              sortAscText: '升序',  
              sortDescText: '降序'  
          },  
          height: 200,  
          width: 500,  
          colModel: cum  
      });  
        
      Ext.get('scroll').on('click', function() {  
          cumgrid.getView().getScrollToTop();  
      });  
        
      Ext.get('focus').on('click', function() {  
          cumgrid.getView().focusCell(2, 3);  
          var cell1 = cumgrid.getView().getCell(2, 3);  
          cell1.style.backgroundColor = 'yellow';  
          cumgrid.getView().focusCell(1, 2);  
          var cell2 = cumgrid.getView().getCell(1, 2);  
          cell2.style.backgroundColor = 'green';  

      });  

      saveButtonClick = function(){
    	 // var _m = store.getModifiedRecords();
    	  var _m = store.modified;
    	  alert(_m.length);
    	  var _temp = [] ;
    	  for(var _i = 0;_i < _m.length;_i ++){
    		  //_temp.push(_m[_i].data);
    		  _temp.push(Ext.apply({}, _m[_i].modified,{id:_m[_i].get("sortId")}));
    	  }
    	  alert(Ext.util.JSON.encode(_temp));
    	  Ext.Ajax.request({
    		  url:"userAction!login.action",
    		  params:{content:Ext.util.JSON.encode(_temp)}
    	  });
      }
      
      Ext.get('savechange').on('click',saveButtonClick);
      
});  
    
  </script>
</head>
<body>
	<div id="cumGrid"> </div>  
    <input type="button" id="scroll" value="添加滚动条"/>  
    <input type="button" id="focus" value="设置单元格" />
    <input type="button" id="savechange" value="保存改变 "/>
</body>
</html>